package com.example.mybatisplus.config.aop;

import com.example.mybatisplus.identifier.generator.CustomIdentifierGenerator;
import com.example.mybatisplus.pojo.Other;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

@Component
@Aspect
public class PojoIdAutoGeneratorAspect {
    @Autowired
    CustomIdentifierGenerator customIdentifierGenerator;

    @Pointcut(value = "execution(* com.example.mybatisplus.mapper.*.*(..))")
    public void pointCut(){
    }
    @Before("pointCut() && args(other)")
    public void test(Other other){
        System.out.println(other);
        if(other.getId()==null){
            other.setId(customIdentifierGenerator.nextId(other));
        }
    }

}
